Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

subnet-check

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

subnet-check

Check if an IPv4 or IPv6 address is contained in the given CIDR subnet

  • 1.10.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
increased by5.47%
Maintainers
1
Weekly downloads
 
Created
Source

subnet-check

This is a fork which works independantly of node.js to be able to be used in the browser.

Check if an IPv4 or IPv6 address is contained in the given CIDR subnet.

  • Small
  • Fast
  • Simple syntax
  • Full test coverage
  • TypeScript-friendly
  • Zero dependencies

Installation

npm i -S louispvb/subnet-check

Usage

const { isInSubnet } = require('subnet-check');

console.log( isInSubnet('10.5.0.1', '10.4.5.0/16') );   // false
console.log( isInSubnet('10.5.0.1', '10.4.5.0/15') );   // true

console.log( isInSubnet('2001:db8:f53a::1', '2001:db8:f53b::1:1/48') );   // false
console.log( isInSubnet('2001:db8:f53a::1', '2001:db8:f531::1:1/44') );   // true

More ways to use it

Test multiple subnets at once

You can pass an array instead of a single subnet.

const inAnySubnet = isInSubnet('10.5.0.1', [ '10.4.5.0/16', '192.168.1.0/24' ]);

This module recognizes several special classes of addresses.

Private addresses

isPrivate(address);

True if the address is in a private/internal address range, such as 192.168.1.1 or similar, or an IPv6 Unique Local Address.

Localhost addresses

isLocalhost(address);

True if the address represents the localhost, such as 127.0.0.1 or ::1.

Keywords

FAQs

Package last updated on 03 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc